﻿using AutoMapper;
using MediatR;
using Traceability.App.Applications.Command.Health;
using Traceability.Domain.Entity;
using Traceability.Domain.Repository;
using Traceability.Enum;

namespace Traceability.App.Applications.CommandHand.Health
{
    public class UpdataHealthCommandHandler : IRequestHandler<UpdataHealthCommand, ApiResult<int>>
    {
        private readonly IBaseRepository<HealthModel> _health;
        private readonly IMapper mapper;

        public UpdataHealthCommandHandler(IBaseRepository<HealthModel> health, IMapper mapper)
        {
            _health = health;
            this.mapper = mapper;
        }

        public Task<ApiResult<int>> Handle(UpdataHealthCommand request, CancellationToken cancellationToken)
        {
            var result = new ApiResult<int>();
            var helth = mapper.Map<HealthModel>(request);
           
            _health.Update(helth);

            result.Message = "修改成功";
            result.Code = ApiEnum.ok;
            return Task.FromResult(result);
        }
    }
}
